<template>
	<view class="container">
		<view class="top">
			<view class="search">
				<input class="search_input" :value='name' data-name="name" @input="input_" placeholder="请输入会员昵称或者电话" />
				<view class="search_button" v-on:click="search"><image src="../../static/images/search.png"></image>搜索</view>
			</view>
		</view>
		<input type="number" class="input_number" placeholder="输入转让的蓝积分" :value='number' data-name="number" @input="input_"/>
		<view class="none" v-if="result.length==0">没有团队成员</view>
		<view class="member" v-for="(item,index) in result" :key="index" v-else>
			<image :src="static_url+'/logo.png'" v-if="item.img.length<10"></image>
			<image :src="item.img" v-else></image>
			<view class="member_con">
				<view class="nickname" v-if="item.nickname!='0'">{{item.nickname}}</view>
				<view class="nickname" v-else>谷牧之道会员</view>
				<view class="phone">{{item.phone}}</view>
			</view>
			<view class="member_total" :data-name="item.nickname" :id="item.member_id" v-if="type==1" v-on:click="replace">替Ta购买</view>
			<view class="member_total" :data-name="item.nickname" :id="item.member_id" v-if="type==2" v-on:click="replace">转让给TA</view>
		</view>
	</view>
</template>
<style>
	/******************/
	.top{width:92%;margin:20px 2% 6px 2%;padding:0 2%;display: flex;justify-content:space-between;align-items: center;}
	.search{width:98%;background: #E1E1E1;border-radius: 35upx;height: 70upx;overflow: hidden;
	        display: flex;justify-content: flex-start;align-items: center;}
	.search_input{width:70%;height:70upx;color: #282828;line-height: 70upx;font-size: 28upx;padding-left:5%;}
	.search_button{width:30%;display: flex;justify-content: center;align-items: center;border-left: 1px solid #282828;font-weight:bold;
				   color: #282828;font-size: 28upx;background: #E1E1E1;height:50upx;line-height: 50upx;}
	.search_button image{width:40upx;height:40upx;margin-right:10upx;}
	.cart{width:70upx;height: 70upx;}
	.none{width:100%;height: 80upx;line-height: 80upx;text-align: center;font-size: 28upx;}
	.input_number{width:92%;margin: 10upx 2%;padding: 10upx 1%;border:1px solid #f4f4f4;border-radius: 10upx;line-height: 50upx;font-size: 28upx;background: #E1E1E1;}
	/******************/
	page,.container{background: #F5F5F5;}
	/**********************************************/
	.total{width:100%;line-height:100upx;text-align: center;font-size: 30upx;background: #FFFFFF;}
	.member{width:92%;margin: 10upx 3%;padding: 10upx 1%;background: #FFFFFF;border-radius:10upx;
	display: flex;justify-content: space-between;align-items: center;}
	.member image{width:80upx;height:80upx;border-radius:40upx;background: #3DE9C7;margin-right: 20upx;}
	.member_con{display: flex;flex-direction: column;justify-content: space-between;align-items: flex-start;width:58%}
	.nickname,.phone,.register{font-size: 28upx;line-height: 40upx;}
	.phone{color: #CCCCCC;}
	.member_total{width: 30%;height: 60upx;line-height: 60upx;text-align: center;border-radius: 30upx;background-image: linear-gradient(#43eac9, #24c3a4);font-size: 28upx;color: #FFFFFF;}
	.price{font-size:30upx;width:100%;text-align: right;}
	.none{width:100%;text-align: center;line-height: 80upx;font-size: 28upx;background: #FFFFFF;}
	.number{color: #ff1844;font-size: 32upx;width:100%;text-align: right;}
</style>
<script>
	export default {
		data() {
			return {
				name:'',
				fixed:0,
				sub_w:'',
				pic_h:'',
				current: 0,
				goods_sort:[],
				start:1,
				result:[],
				type:1,
				number:'',
				url: getApp().globalData.url,
				static_url:getApp().globalData.static
			}
		},
		onLoad(e) {
			var res = uni.getSystemInfoSync();
			var w = res.windowWidth;
			this.sub_w = 8*95+"px";
			this.pic_h = w*0.94*0.48+"px";
			this.type  = parseInt(e.type);
			uni.removeStorageSync("replace_id");
		},
		methods: {
			replace:function(e)
			{
				var id = e.currentTarget.id;
				var name = e.currentTarget.dataset.name;
				if(this.type==1)
				{
					uni.showModal({
						title:"操作提示",
						content:"以下操作，您将代替“"+name+"”完成下单支付，\r\n点击确定,进入商城页面购买",
						success: (res) => {
							if(res.confirm)
							{
								uni.setStorageSync("replace_id",id);
								uni.switchTab({
									url:"../mall/index"
								})
							}
						}
					})
				}
				else
				{
					uni.showModal({
						title:"操作提示",
						content:"将向“"+name+"”转让蓝积分"+this.number+"，\r\n点击确定,立即执行",
						success: (ress) => {
							if(ress.confirm)
							{
								var member_id = uni.getStorageSync("member_id");
								uni.request({
									url: this.url+"/wechat_member_integral_donation",
									data: {member_id:member_id,recommend_id:id,balance:this.number,type:2},
									header: {
									  'Content-Type': 'application/json'
									},
									success: function (res) 
									{
										if(res.data.status==1)
										{
											uni.showToast({
												title:'操作成功'
											})
											uni.redirectTo({
												url:"balance"
											})
										}
										else
										{
											uni.showModal({
												title:"操作提示",
												content:res.data.msg,
												showCancel:false
											})
										}
									}
								})
							}
						}
					})
				}
				
			},
			input_:function(e)
			{
				if(e.currentTarget.dataset.name=="name")
				{
					this.name = e.target.value;
				}
				if(e.currentTarget.dataset.name=="number")
				{
					this.number = e.target.value;
				}
			},
			search:function()
			{
				if(this.name=="")
				{
					uni.showToast({
						title:"不能为空",
						duration:2000
					})
				}
				else
				{
					this.initialize();
				}
			},
			initialize:function()
			{
				var that = this;
				var member_id = uni.getStorageSync("member_id");
				uni.request({
					url: this.url+"/wechat_member_search",
					data: {member_id:member_id,name:this.name},
					header: {
					  'Content-Type': 'application/json'
					},
					success: function (res) 
					{
						if(res.data.status==1)
						{
							that.result = res.data.result;
						}
						else
						{
							uni.showToast({
								title:"没有查询到",
								duration:1500
							})
						}
					}
				})
			}
		}
	}
</script>